package com.qf.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义的异常处理器  （全局统一处理异常的）
 *
 * Handler:处理器
 * Exception：异常
 * Resolver：处理
 * @author lixu
 */
public class CustomExceptionResolver implements HandlerExceptionResolver {


    /**
     *
     * @param request current HTTP request
     * @param response current HTTP response
     * @param handler 是哪个Controller层报的这个错误  userController OrderController
     * time of the exception (for example, if multipart resolution failed)
     * @param ex the exception that got thrown during handler execution
     * @return
     */
    @Override
    public ModelAndView resolveException(HttpServletRequest request,
                                         HttpServletResponse response,
                                         Object handler, Exception ex) {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("error/error");
        //mav.addObject("message",ex.getMessage());
        mav.addObject("message","不好意思，我迷路！");
        return mav;
    }
}
